package com.changpay.zywy.ui.activity.count
import com.changpay.zywy.R
import com.changpay.zywy.base.BaseMvpActivity
import com.changpay.zywy.mvp.contract.CountTotalContract
import com.changpay.zywy.bean.CountBean
import com.changpay.zywy.mvp.presenter.CountTotalPresenter
import com.changpay.zywy.utils.DateUtil
import com.changpay.zywy.utils.StringUtil
import kotlinx.android.synthetic.main.activity_count_all.*
import kotlinx.android.synthetic.main.title_layout.*

class CountTotalActivity : BaseMvpActivity<CountTotalContract.View, CountTotalContract.Presenter>(),
    CountTotalContract.View {

    var string_array_one: Array<String> = arrayOf("交易量", "今日交易", "总交易")
    var string_array_two: Array<String> = arrayOf("激活量", "今日激活(台)", "总激活(台)")
    var string_array_three: Array<String> = arrayOf("收益量", "今日收益", "总收益")

    private var type: Int = 0

    override fun showStats(data: CountBean) {
        data.let {
            val personals = it.present?.personals?.toDouble()!!
            val groups = it.present?.groups?.toDouble()!!
            val personTotal = personals + groups

            if (type == 2) {
                count_total_one.text = personTotal.toInt().toString()
                count_number_tv_one.text = it.present?.personals
                count_number_tv_two.text = it.present?.groups
            } else {
                count_total_one.text = "￥" + StringUtil.formatDouble(personTotal)
                count_number_tv_one.text = "￥" + StringUtil.formatDouble(personals)
                count_number_tv_two.text = "￥" + StringUtil.formatDouble(groups)
            }
            if (personTotal > 0) {
                progress_one.setSweepAngle((groups / personTotal).times(360).toInt())

            } else {
                progress_one.setSweepAngle(180)
            }
        }

        data.total.let {
            val personals = it?.personal_total?.toDouble()!!
            val groups = it.group_total?.toDouble()!!
            val total = personals + groups
            if (type == 2) {
                count_total_two.text = total.toInt().toString()
                count_number_tv_three.text = it.personal_total
                count_number_tv_four.text = it.group_total
            } else {
                count_total_two.text = "￥" +StringUtil.formatDouble(total)
                count_number_tv_three.text = "￥" + StringUtil.formatDouble(personals)
                count_number_tv_four.text ="￥" + StringUtil.formatDouble(groups)
            }
            if (total > 0) {
                progress_two.setSweepAngle((groups / total).times(360).toInt())
            } else {
                progress_two.setSweepAngle(180)

            }
        }
    }


    override fun createPresenter(): CountTotalContract.Presenter = CountTotalPresenter()

    override fun attachLayoutRes(): Int = R.layout.activity_count_all


    override fun initData() {

    }

    override fun start() {
        val param = hashMapOf<String, String>()
        val today = DateUtil.getToday()
        param["key"] = token
        param["type"] = type.toString()
        param["search_date_star"] = today
        param["search_date_end"] = today
        param["gc_id"] = intent.getStringExtra("gc_id")
        mPresenter?.getStats(param)
    }


    override fun initView() {
        super.initView()
        tv_title.text = "总量图"
        type = intent.getIntExtra("type", 1)
        when (type) {
            1 -> {
                count_title.text = string_array_one[0]
                count_title_one.text = string_array_one[1]
                count_title_two.text = string_array_one[2]
            }
            2 -> {
                count_title.text = string_array_two[0]
                count_title_one.text = string_array_two[1]
                count_title_two.text = string_array_two[2]
            }
            3 -> {
                count_title.text = string_array_three[0]
                count_title_one.text = string_array_three[1]
                count_title_two.text = string_array_three[2]
            }
        }
        iv_back.setOnClickListener { finish() }
    }

}
